<template>
  <el-dialog
    title="添加"
    :visible.sync="dialogVisible"
    :before-close="handleClose"
    width="30%"
  >
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="员工名称" prop="user_name">
        <el-input v-model="ruleForm.user_name"></el-input>
      </el-form-item>
      <el-form-item label="员工职称" prop="user_job">
        <el-input v-model="ruleForm.user_job"></el-input>
      </el-form-item>
      <el-form-item label="员工经验" prop="user_experience">
        <el-input v-model="ruleForm.user_experience"></el-input>
      </el-form-item>
      <el-form-item label="员工薪资" prop="user_money">
        <el-input v-model="ruleForm.user_money"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="submitForm('ruleForm')"
          >立即创建</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
export default {
  props: ["dialogVisible","user_mes"],
  data() {
    return {
      ruleForm: {
        user_name: "",
        user_job: "",
        user_state: false,
        user_experience: "",
        user_money: "",
      },
      rules: {
        user_name: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        user_job: [
          { required: true, message: "请输入职称", trigger: "change" },
        ],
        user_experience: [
          { required: true, message: "请输入工作年限", trigger: "change" },
        ],
        user_money: [
          { required: true, message: "请输入薪资", trigger: "change" },
        ],
      },
    };
  },
  methods: {
    handleClose() {
      this.$emit("closeDialog");
    },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.handleClose()
            this.user_mes.push(this.ruleForm)
          } else {
           
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
  },
};
</script>
